#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/irq.h>

#include <asm/ptrace.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("chzhou");

void my_softirq_action(struct softirq_action *data)
{
    dump_stack();
    printk("[%s %d ]\n", __FUNCTION__, __LINE__);
    return;
}

static irqreturn_t irq_handle(int irq, void *dev_id, struct pt_regs *regs)
{
    int flag;

    raise_softirq(MY_SOFTIRQ); //触发软中断
    printk("[%s %d ] handle irq %s\n", __FUNCTION__, __LINE__, dev_id);

    return 0;
}

int test_init(void)
{
    int ret = 0;
    
    open_softirq(MY_SOFTIRQ, my_softirq_action); //注册软中断
    set_irq_type(IRQ_EINT8, IRQ_TYPE_EDGE_RISING); //EINT8中断设为上升沿中断, key 0
    ret = request_irq(IRQ_EINT8, irq_handle, IRQF_SHARED, "my button irq", "chzhou123"); //注册EINT0中断

    if (ret) {    
        printk("request irq failed.\n");
        return -EBUSY;
    }

    printk("[%s %d ]\n", __FUNCTION__, __LINE__);
    return ret;
}

void test_exit(void)
{
    free_irq(IRQ_EINT8, "chzhou123");
    printk("[%s %d ]\n", __FUNCTION__, __LINE__);
}

module_init(test_init);
module_exit(test_exit);

// http://blogold.chinaunix.net/u4/120285/showart_2534620.html
